<?php
//require_once("ModelConfig.php");
//require_once("Logger.php");

/**
 * Comic.solor.cn Model - COMICDB.php
 */

/**
 * DB class is the class for getting PDO::Mysql db handler
 *
 * @access public
 */
class DB
{
    /**
     * 数据库句柄
     *
     * @access public
     * @var resource
     */
    public static $db = null;

    // --- OPERATIONS ---

    /**
     * Get instance of PDO .... a static method
     *
     * @access public
     * @return resource
     */
    public static function instance()
    {
        $returnValue = null;

		$dsn = "mysql:host=" . C_DB_HOST . ";dbname=" . C_DB_DB;
		
		if (self::$db == null)
		{

			try
			{
				self::$db = new PDO($dsn, C_DB_USER, C_DB_PASS);
			}
			catch (PDOException $e)
			{
				//TODO add error handler function
				$logger = Logger::instance();
				$logger->log($e->getMessage());
			}
		}
		$returnValue = &self::$db;

        return $returnValue;
    }

	private function __construct()
	{
	}

} /* end of class DB */

?>
